package com.lechi.web.runner;

import com.lechi.web.listener.FileJnotifyAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * The type Watch file runner.
 */
@Slf4j
@Component
@Order(8)
public class WatchFileRunner implements CommandLineRunner {

    @Autowired
    private FileJnotifyAdapter jnotifyAdapter;
//
//    private final Timer timer = new Timer();
//
//    private final TimerTask timerTask = new TimerTask() {
//        @Override
//        public void run() {
//            ExpireCacheUtil.getCache().asMap().keySet().forEach(key -> {
//                Optional<Date> ifPresent = Optional.ofNullable(ExpireCacheUtil.getCache().getIfPresent(key));
//                if (ifPresent.filter(endTime -> new Date().getTime() - endTime.getTime() >= 60000L).isPresent()) {
//                    ExpireCacheUtil.getCache().invalidate(key);
//                }
//            });
//        }
//    };

    @Override
    public void run(String... args) throws Exception {
//        FileAlterationMonitor monitor = new FileAlterationMonitor(timeout);
//        FileAlterationObserver observer = new FileAlterationObserver(this.filePath);
//        observer.addListener(fileAlterationListener);
//        monitor.addObserver(observer);
//        monitor.start();
        jnotifyAdapter.beginWatch();
//        timer.schedule(timerTask, 60000L,60000L);
    }
}
